/**
 * 
 */
package com.sip.scanadapter.factory;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.sip.scanadapter.strategy.Stratergy;

/**
 * @author Dhanushka Ariyasingha
 * 
 */
public class ScanStrategyFactory {

	private static ScanStrategyFactory factory = null;

	private ApplicationContext applicationContext = null;

	private ScanStrategyFactory() {

		String[] locations = getConfigLocations();
		applicationContext = new FileSystemXmlApplicationContext(locations);

	}

	public static ScanStrategyFactory getInstance() {

		if (null == factory) {
			factory = new ScanStrategyFactory();
		}

		return factory;
	}

	public Stratergy getStrategy(final String startergy) {

		return (Stratergy) applicationContext.getBean(startergy);
	}

	protected String[] getConfigLocations() {

		return new String[] { "classpath:config/application-context.xml", "classpath:config/scan-strategy-context.xml" };
	}

}
